<%@ page import="com.ridbor001.demo.bean.RDBUser" %>
<!-- 新增User类导入 -->
<%@ page import="com.ridbor001.demo.bean.RDBTeacher" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.ridbor001.demo.bean.RDBStudent" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<% RDBUser user = (RDBUser) session.getAttribute("user");
if (user == null) {
response.sendRedirect("rDBLogin.jsp"); return; } %>
<!DOCTYPE html>
<html>
<head>
  <link href="./css/rDBDashboard.css" rel="stylesheet" />
</head>
<body>
<button class="theme-toggle" onclick="toggleTheme()">🌙</button>
<div class="container">
  <div class="user-info">
    <h2>欢迎，${sessionScope.user.name}！</h2>
    <c:choose>
      <c:when test="${sessionScope.user['class'].simpleName == 'Student'}">
        <p>学号：${sessionScope.user.studentId}</p>
      </c:when>
      <c:when test="${sessionScope.user['class'].simpleName == 'Teacher'}">
        <p>教师ID：${sessionScope.user.teacherId}</p>
      </c:when>
    </c:choose>
    <a href="logout" class="logout-link">退出登录</a>
  </div>

  <div class="menu-card">
    <h3>功能导航</h3>
    <div class="menu-links">
      <c:choose>
        <c:when test="${sessionScope.user.teacher}">
          <a href="gradeManage" class="menu-link">成绩管理</a>
          <a href="evaluation?action=stats" class="menu-link">查看评教</a>
        </c:when>
        <c:when test="${sessionScope.user.student}">
          <a href="gradeManage" class="menu-link">我的成绩</a>
          <a href="evaluation?action=list" class="menu-link">进行评教</a>
        </c:when>
        <c:when test="${sessionScope.user.admin}">
          <a href="courseManage" class="menu-link">科目管理</a>
        </c:when>
      </c:choose>
    </div>
  </div>
</div>

<script>
  // 初始化主题
  function initTheme() {
    const savedTheme = localStorage.getItem('theme') || 'dark';
    const isLight = savedTheme === 'light';
    document.body.classList.toggle('light-mode', isLight);
    document.querySelector('.theme-toggle').textContent = isLight ? '☀️' : '🌙';
  }

  // 切换主题
  function toggleTheme() {
    const body = document.body;
    const isLight = !body.classList.contains('light-mode');
    body.classList.toggle('light-mode');
    localStorage.setItem('theme', isLight ? 'light' : 'dark');
    document.querySelector('.theme-toggle').textContent = isLight ? '☀️' : '🌙';
  }

  // 页面加载时初始化
  window.addEventListener('load', initTheme);
</script>
</body>
</html>

